package com.example.websockettest.webSocket.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

//挖空单词
public class WordToShow extends 通用操作数据库{
   public static Map<String,Object> wordsToShow(String word,String mean){
        Map<String,Object> objectMap=new HashMap<>();
        StringBuilder wordbuffer=new StringBuilder(word);
        objectMap.put("word",word);
        Random random=new Random();
       int a=random.nextInt(word.length());
        if(word.length()>=6){//词长挖两个
            int b=random.nextInt(word.length());
            while (a==b){
                b=random.nextInt(word.length());
            }
            wordbuffer.setCharAt(b,'_');
        }
        wordbuffer.setCharAt(a,'_');
        objectMap.put("showWord",wordbuffer);
        objectMap.put("chinese",mean);
        return objectMap;
    }
public static void main(String[] args){
       System.out.println(JSONObject.toJSONString(wordsToShow("iampy","你好")));
}
}
